package tw.org.iii.dataaccesssample.data;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class CDbManager extends SQLiteOpenHelper{

	public CDbManager(Context context) {
		super(context, "dbMeeting.db", null,1);
		
	}
	
	public Cursor GetBySql(String strSql){
		return getWritableDatabase().rawQuery(strSql, null);
	}
	
	public void UpdateData(String strTableName,ContentValues valueData,
			long lngPK){
		getWritableDatabase().update(
				strTableName, 
				valueData, 
				"_id="+String.valueOf(lngPK),
				null);
	}
	
	public void DeleteData(String strTableName,long lngPK){
		getWritableDatabase().delete(
				strTableName, 
				"_id="+String.valueOf(lngPK),
				null);
	}
	
	public void newData(String strTableName,ContentValues valueData){
		getWritableDatabase().insert(strTableName, null, valueData);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String strSchema="CREATE TABLE tMeeting (";
		strSchema+=" _id INTEGER PRIMARY KEY, ";
		strSchema+=" fId TEXT NOT NULL,";
		strSchema+=" fSubject TEXT NOT NULL,";
		strSchema+=" fDate TEXT, ";
		strSchema+=" fTime TEXT, ";
		strSchema+=" fLocation TEXT) ";
		
		db.execSQL(strSchema);
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}

}
